import { Controller } from "../../mvc/core/Controller";
import { PlayerEvent } from "../scene/events/PlayerEvent";
import { SkillInfo } from "../model/SkillInfo";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { DataEvent } from "../events/DataEvent";
import { EventName } from "../mvc/EventName";
import { FishIconView } from "../view/fishing/FishIconView";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { RolePlayer } from "../scene/player/entity/RolePlayer";
import { SkillLevelGetInfo } from "../resource/info/SkillLevelGetInfo";
type int = number;
//class SkillLevelGetController
    
    export  class SkillLevelGetController extends Controller
    {
       

        /* internal  */onSkillListRes(arg1: Array<any>): void
        {
            this.updateLevelGetSkill();
            return;
        }

        /* internal  */onRoleLevelUpdate(arg1: PlayerEvent): void
        {
            this.updateLevelGetSkill();
            return;
        }

        /* internal  */onRoleCareerUpdate(arg1: Object): void
        {
            this.updateLevelGetSkill();
            return;
        }

        /* internal  */onSkillFishLearned(arg1: SkillInfo): void
        {
            this.updateLevelGetSkill(arg1.tSkill.skillId);
            return;
        }

        /* internal  */onSkillOreLearned(arg1: SkillInfo): void
        {
            this.updateLevelGetSkill(arg1.tSkill.skillId);
            return;
        }

        /* internal  */onSkillXPLearned(arg1: SkillInfo): void
        {
            this.updateLevelGetSkill(arg1.tSkill.skillId);
            Dispatcher.dispatchEvent(new DataEvent(EventName.AddToShortcutsByReq, arg1.tSkill));
            return;
        }

        /* internal  */updateLevelGetSkill(arg1: int=0): void
        {
            var loc1=cache.skillLevelGet.getCurrentSkill(arg1);
            if (loc1 != null) 
            {
                if (!this._lastSkillInfo || !(this._lastSkillInfo == loc1)) 
                {
                    FishIconView.instace.updateData(loc1);
                    Dispatcher.dispatchEvent(new DataEvent(EventName.SkillLevelGetShow));
                    this._lastSkillInfo = loc1;
                }
                if (cache.role.entityInfo.level >= loc1.needLevel) 
                {
                    FishIconView.instace.showLightMask();
                }
                else 
                {
                    FishIconView.instace.hideLightMask();
                }
            }
            else 
            {
                FishIconView.instace.hide();
                this._lastSkillInfo = null;
            }
            return;
        }

        protected /* override */ initServer(): void
        {
            super.initServer();
            NetDispatcher.addCmdListener(ServerCommand.SkillListRes, this.onSkillListRes);
            RolePlayer.instance.addEventListener(PlayerEvent.RoleLevelUpdate, this.onRoleLevelUpdate);
            NetDispatcher.addCmdListener(ServerCommand.SkillFishLeared, this.onSkillFishLearned);
            NetDispatcher.addCmdListener(ServerCommand.SkillOreLeared, this.onSkillOreLearned);
            NetDispatcher.addCmdListener(ServerCommand.SkillXPLearned, this.onSkillXPLearned);
            NetDispatcher.addCmdListener(ServerCommand.RoleCareerUpdate, this.onRoleCareerUpdate);
            return;
        }

        private /* var */_lastSkillInfo: SkillLevelGetInfo;
    }
